#include<bits/stdc++.h>
#define int long long
using namespace std;
#define getchar() (p1 == p2 && (p2 = (p1 = buf1) + fread(buf1, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
char buf1[1 << 23], *p1 = buf1, *p2 = buf1, ubuf[1 << 23], *u = ubuf;
namespace IO
{
	template<typename T>
	void read(T &_x){_x=0;int _f=1;char ch=getchar();while(!isdigit(ch)) _f=(ch=='-'?-1:_f),ch=getchar();while(isdigit(ch)) _x=_x*10+(ch^48),ch=getchar();_x*=_f;}
	template<typename T,typename... Args>
	void read(T &_x,Args&...others){Read(_x);Read(others...);}
	const int BUF=20000000;char buf[BUF],to,stk[32];int plen;
	#define pc(x) buf[plen++]=x
	#define flush(); fwrite(buf,1,plen,stdout),plen=0;
	template<typename T>inline void print(T x){if(!x){pc(48);return;}if(x<0) x=-x,pc('-');for(;x;x/=10) stk[++to]=48+x%10;while(to) pc(stk[to--]);}
}
using namespace IO;
const int N = 1e5+10;
int t,n,a[N],b[N],v[N],ans,op;
signed main()
{
	freopen("game.in","r",stdin);
	freopen("game.out","w",stdout);
	read(t);
	while(t--)
	{
		read(n); ans = 0;
		for(int i = 1;i <= n;i++) read(a[i]);
		for(int i = 1;i <= n;i++) read(b[i]);
		for(int i = 1;i <= n;i++) ans += abs(a[i]-b[i]);
		op = 0;
		for(int i = 1;i <= n;i++)
			if(a[i] == 0 && b[i] != 0) { op = 1;break; }
		if(op) { print(-1),pc('\n');continue; }
		print(ans),pc('\n');
	}
	flush();
	return 0;
}




